<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/global/global-head.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>吉车惠后台管理系统</title>
    <%@include file="/global/global-other.jsp" %>
    <script type="text/javascript">
        $(function() {
            parent.$.messager.progress('close');
            submitForm = function( $dialog, $gird){
                $('#bn_advertisement_form').form('submit',{
                    url:'${ctx}/bn/advertisement/insert',
                    queryParams:{_m:'exec'},
                    onSubmit:function(){
                        if($(this).form('enableValidation').form('validate')){
                            return true;
                        }else{
                            return false;
                        }
                    },
                    success:function(data){
                        var json =  eval("(" +data+ ")");
                        if(statusMsg(json)){
                            parent.$.messager.alert("提示","保存成功！","info",function(){
                                $dialog.dialog('destroy');
                                $gird.datagrid('reload');
                            });
                        }
                    }
                });
            };


            $("#inputfile").change(function(){
                var filedata = $(this).val();
                if (filedata == "" || filedata == null) {
                    parent.$.messager.alert("提示", errMsg("请选择上传文件！"), "error");
                    return;
                }

                var uploadFileType="PNG|JPG";
                var array = filedata.split(".");
                var type = array[1];
                if(uploadFileType.indexOf(type.toUpperCase())==-1){
                    parent.$.messager.alert("提示", errMsg("格式不正确，只能为PNG|JPG当中的一种！"), "error");
                    return
                }
                parent.$.messager.progress({
                    text : '正在上传，请稍后...'
                });

                $("#upload_form").ajaxSubmit({
                    type: "POST",
                    url:'${ctx}/bn/advertisement/insert?_m=upload&r='+Math.random(),
                    success: function(data){
                        parent.$.messager.progress('close');
                        if(statusMsg(data)){
                            $("#pic").val(data.msg);
                            var h = '<img src="'+data.msg+'" width="350"/>';
                            $("#imgUrl").html(h);
                        }
                    },
                    error:function(){
                        parent.$.messager.progress('close');
                    }
                });

            })
        });
    </script>
</head>
<body>
<div class="form-box">
    <div class="form-body">
        <form role="form" method="POST" name="bn_advertisement_form" id="bn_advertisement_form" class="easyui-form form form-horizontal" data-options="novalidate:true" enctype="multipart/form-data">
            <input type="hidden" id="pic" name="pic" value=""/>

            <div class="seg-title">
                <div class="seg-title-box">
                    <ul>
                        <li class="seg-title-box-icon" ><img src="${ctx }/assets/images/communication.gif"/></li>
                        <li class="seg-title-box-text">基本信息</li>
                    </ul>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">广告主名称：</p>
                    <p class="star">*</p>
                </label>
                <div class="col-sm-8">
                    <input type="text" id="advertiserId" name="advertiserId" value="" class="form-control easyui-combobox" style="width:100%;height:34px;line-height:34px;" data-options="valueField: 'advertiserId',textField: 'advertiserName',url:'${ctx}/bn/advertisement/getadvertiser?_m=exec',editable:false" required="required"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">广告全称：</p>
                    <p class="star">*</p>
                </label>
                <div class="col-sm-8">
                    <input type="text" id="adName" name="adName"  class="form-control easyui-validatebox" style="width:100%;height:34px;line-height:34px;" required="required" validType="length[1,50]">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">广告简称：</p>
                    <p class="star">*</p>
                </label>
                <div class="col-sm-8">
                    <input type="text" id="adShortName" name="adShortName"  class="form-control easyui-validatebox" style="width:100%;height:34px;line-height:34px;" required="required" validType="length[1,50]">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">访问地址：</p>
                </label>
                <div class="col-sm-8">
                    <input type="text" id="url" name="url"  class="form-control easyui-validatebox" style="width:100%;height:34px;line-height:34px;" validType="length[1,200]">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">广告内容：</p>
                </label>
                <div class="col-sm-8">
                    <textarea id="content" name="content" class="autosize form-control" validType="length[1,200]"></textarea>
                </div>
            </div>
        </form>
        <form role="form" name="upload_form" id="upload_form" class="easyui-form form form-horizontal" data-options="novalidate:true"  enctype="multipart/form-data">
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    <p class="label-txt">广告图片：</p>
                </label>
                <div class="col-sm-8">
                    <button type="button" class="btn btn-info btn-squared btn-lg" onclick="getElementById('inputfile').click();">
                        图片上传 <i class="fa fa-arrow-circle-o-up fa-1x"></i>
                    </button>
                    <input type="file" name="inputfile"　multiple="multiple" style="opacity:0;filter:alpha(opacity=0);height:5px;" id="inputfile"/>
                    <div id="imgUrl"  style="width:500px;text-align: center;text-align: left;">
                        图片预览区域
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>